<?php
/**
 * 
 * model for the user specific shoes
 * @author Simon
 *
 */
class ShoeUser_model extends CI_Model {  
  
	/**
	 * constructor
	 */
    function ShoeUser_model()  
    {  
    	$this->load->database();
    }  
  
    /**
     * returns all user shoes from the database
     */
    function getAllShoes()  
        {  
        	//Query the data table for every record and row
        	$query = $this->db->get('shoeuser');
        	
        	if ($query->num_rows() < 1)
        	{
        		//show_error('Database is empty!');
        	}else{
        		return $query->result();
        	}   
        }  
        
     /**
      * 
      * returns one shoe from the user by id
      * @param int $id user shoe id
      */   
     function getUserShoeByID($id)
     {
     	$query = $this->db->get_where('shoeuser', array('ID' => $id));
     	
     	if ($query->num_rows() < 1)
     	{
     	//show_error('Database is empty!');
     	}else{
     		return $query->row();
     	}
     }
     
     /**
      * returns all user shoes frum one user by the user id
      * @param int $userid
      */
     function getAllUserShoesFromUser($userid)
     {
     	$query = $this->db->get_where('shoeuser', array('UserID' => $userid));
     
     	if ($query->num_rows() < 1)
     	{
     		//show_error('Database is empty!');
     	}else{
     		return $query->result();
     	}
     }
     
     /**
      * adds one user shoe. returns true if the transaction was sucessfull
      * @param int $userid
      * @param int $shoeid
      */
     function addUserShoe($userid,$shoeid)
     {
	    $data = array(
		   'Kilometer' => 0,
		   'UserID' => $userid,
		   'ShoeID' => $shoeid
		);
	
		return $this->db->insert('shoeuser', $data); 
     }
     
     function updateUserShoe($userShoeID, $userid,$shoeid, $kilometer){
	    $data = array(
		   'Kilometer' => $kilometer,
		   'UserID' => $userid,
		   'ShoeID' => $shoeid
		);
	
	    
	    $this->db->where('ID', $userShoeID);
		return $this->db->insert('shoeuser', $data); 
     	
     }
     
     /**
      *  deletes one unser shoe by the id. returns true if the transaction was sucessfull
      * @param int $id
      */
     function deleteUserShoe($id)
     {
     	$this->db->delete('shoeuser', array('ID' => $id)); 
     }
  
}  
?>  